package com.cnpc.ds.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cnpc.ds.entity.CommCrustressLog;
import com.cnpc.ds.mapper.CommCrustressLogMapper;
import com.cnpc.ds.service.ICommCrustressLogService;
import com.cnpc.ds.utils.PageInfoUtil;
import com.cnpc.eisc.base.pojo.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 日志服务实现类
 * </p>
 *
 * @author jyq
 * @since 2022-06-15
 */
@Service
public class CommCrustressLogServiceImpl extends ServiceImpl<CommCrustressLogMapper, CommCrustressLog> implements ICommCrustressLogService {

    @Override
    public PageInfo<CommCrustressLog> query(PageInfo<CommCrustressLog> page, String sort, Boolean isAsc, CommCrustressLog commCrustressLog) {
        QueryWrapper<CommCrustressLog> queryWrapper = Wrappers.query(commCrustressLog);
        if(!sort.contains("_")){
            sort = StrUtil.toUnderlineCase(sort).toUpperCase();
        }
        queryWrapper.orderBy(true, isAsc, sort);
        Page<CommCrustressLog> wherePage = new Page<>(page.getPageNum(), page.getPageSize());
        Page<CommCrustressLog> entityPage = this.baseMapper.selectPage(wherePage, queryWrapper);
        return PageInfoUtil.getPageInfo(entityPage);
    }

    @Override
    public Integer add(CommCrustressLog commCrustressLog) {
        int res = baseMapper.insert(commCrustressLog);
        return res;
    }

    @Override
    public Integer delete(List<Long> ids) {
        int res = baseMapper.deleteBatchIds(ids);
        return res;
    }

    @Override
    public Integer modify(CommCrustressLog commCrustressLog) {
        int res = baseMapper.updateById(commCrustressLog);
        return res;
    }

    @Override
    public CommCrustressLog detail(Long id) {
        CommCrustressLog entity = baseMapper.selectById(id);
        return entity;
    }
}
